home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / SECURITY / 0504.ZIP / PC-CRYP2.DOC < prev    next >
Text File  |  1985-05-21  |  24KB  |  460 lines

  1.                                                            Cover
  2.  
  3.                              PC-CRYP2
  4.  
  5.       PC-CRYP2 supercedes and replaces all versions of PC-CRYP1
  6.  
  7.                      Version 3.2  20 May 1985
  8.  
  9.                Data Encryption and Decryption Program
  10.  
  11.                    Copyright 1983, 1984, 1985 by
  12.                         James T. Demberger
  13.                       7280 60th Avenue North
  14.                      St Petersburg, FL  33709
  15.                           813-546-1182
  16.  
  17.      This is a user supported program.  If you use PC-CRYP2 and find it
  18. of value, your contribution of any amount will be appreciated.  You are
  19. are encouraged to copy and share this program with other users so long
  20. as the program is not distributed in modified form and this notice is
  21. not bypassed or removed.
  22.  
  23.      PC-CRYP2 is NOT a public domain program.  The compiled program
  24. PC-CRYP2.EXE and the documenatation PC-CRYP2.DOC may be freely copied
  25. HOWEVER the BASIC source code for PC-CRYP2 may not be copied except for
  26. archive or working copies for personal non-profit use as outlined in
  27. copyright regulations.  The BASIC source code may not be made available
  28. thru clubs or user groups, program libraries or on remote access data
  29. bases or bulletin boards.  A distribution diskette with the PC-CRYP2.EXE
  30. file, the PC-CRYP2.DOC file and the BASIC source code PC-CRYP2.BAS file
  31. is available from the author for $15.00 (diskette, postage and mailer
  32. included).
  33.  
  34.                                  Index
  35.  
  36.                    Introduction                 Cover
  37.                    Vernam Encryption              1
  38.                    System Requirements            1
  39.                    System Setup                   2
  40.                    Running PC-CRYP2               2
  41.                    Encrypt & Decrypt Test Strings 3
  42.                    Processing Files               4
  43.                         Sequential Files          4
  44.                         Direct Files              5
  45.                    Transmitting Encrypt Files     6
  46.                    Double Encryption              7
  47.                    Miscellaneous                  8
  48.  
  49.                               Introduction
  50.  
  51.      The program has two main functions:  demonstration of the Vernam
  52. encryption and decryption process using test character strings and the
  53. encryption and decryption of both sequential and random access files.
  54. All encryption, decryption and file or record processing is done within
  55. subroutines.  These subroutines may be merged into other file processing
  56. programs if PC-CRYP2 does not provide the required file processing
  57. capability.
  58.                                                                  Page 1
  59.                           Vernam Encryption
  60.  
  61.      Back in 1917, Gilbert S. Vernam developed an encryption process
  62. for messages punched in paper tape using Baudot or five channel
  63. teletype code.  He used the electro-mechanical equivalent of a logical
  64. exclusive OR operation (XOR) on each character code in a message tape
  65. and a corresponding character code in a key tape to produce a third
  66. tape with the encrypt message.  Decryption used the same process except
  67. that a tape with the encrypt message and a copy the key tape were XORed
  68. to produce the decrypt message.  The program uses essentially the same
  69. process even to the extent of using a five bit pattern to encrypt and
  70. decrypt data.
  71.  
  72.      One problem with the original Vernam process related to the key
  73. tapes.  For a secure system, the characters in the key tapes had to be
  74. in random order and the number of characters in a key tape had to
  75. exceed the number of characters in the message to be encrypt.  The
  76. solution to the length problem was to use the XORed output of two
  77. tapes, one with 999 characters and the other with 1000 characters, to
  78. create a key with an effective length of 999,000 characters.  The
  79. program generates as many random characters as are required for any
  80. practical message length.  There is no need to store the randomly
  81. generated characters since the generation process will consistently
  82. produce the same characters in the same sequence.
  83.  
  84.      Another problem related to six of the 32 teletype codes.  These
  85. six codes were teletype control codes (shift up, shift dowm etc.) and
  86. required special consideration.  XORing two eight bit ASCII codes
  87. creates the same problem in that the resulting value may be a display,
  88. printer or communications control code.  The five bit code with binary
  89. values from 0 thru 31 used by Vernam offers a solution to this problem.
  90. XORing any number from 0 thru 31 with any of the ASCII codes 32 thru
  91. 255 never results in a value less than 32.  The program uses only XOR
  92. values or codes from 0 thru 31; encryption will not produce any codes
  93. that correspond to control codes for the display, printer or a
  94. communications link.
  95.  
  96.      The program's counterpart of the two key tapes is a set of three
  97. counters that are used as indexes or pointers to a code list, in random
  98. order, of 103 codes that range in value from 0 thru 31.  The counters
  99. are reset to 1 when they reach a maximum count of 97, 101 and 103
  100. respectively.  The effective key length is 1,009,091; the least common
  101. multiple of the prime numbers 97, 101 and 103.  The counters point to
  102. the three codes that are XORed with an ASCII character code for
  103. encryption and decryption.
  104.  
  105.                          System Requirements
  106.  
  107.      The program is written in IBM PC BASIC and runs on an IBM PC with
  108. 64 K or more of memory, an IBM or MX-80 printer, either a color or
  109. monochrome display and one or more disk drives.
  110.                                                                  Page 2
  111.                              System Setup
  112.  
  113.      PC-CRYP2 may be run as interpreted or compiled BASIC.  Interpreted
  114. BASIC will encrypt or decrypt at a rate of 12 or more characters per
  115. second while compiled BASIC will encrypt or decrypt at a rate or 350 or
  116. more characters per second.  Copy PC-CRYP2.BAS to a system or data
  117. diskette if you are only interested in seeing how the program runs.
  118. Copy PC-CRYP2.EXE to a data or system diskette if you want to take
  119. advantage of the faster encryption and decryption rate.
  120.  
  121.                             Running PC-CRYP2
  122.  
  123. Using interpreted BASIC - From DOS ready key [dr:]BASIC [dr:]PC-CRYP2
  124.      then press the Enter key.
  125.  
  126. Using compiled BASIC - From DOS ready key [dr:]PC-CRYP2 then press the
  127.      Enter key.
  128.  
  129.      A default option is shown for the response to most prompts
  130. displayed by the program.  As an example, a prompt for a yes or no
  131. response will display "y/N".  Press Enter to take the no default option
  132. indicated by the uppercase N.  Either a lower case y or an uppercase Y
  133. must be pressed for the yes response.  If only lower case options or no
  134. option is shown, an entry other than the Enter key must be used.
  135.  
  136.      The first two displays are a "USERWARE" commercials.  These
  137. displays are followed by the password entry display:
  138.  
  139.                         SELECT NEW PASSWORD
  140.  
  141.             Press V for a visible display of Password or
  142.                 press Enter for non-visible display _
  143.  
  144.                    Old Password is
  145.  
  146.                    Enter New Password _
  147.  
  148.                    Code List for Password
  149.  
  150.      All encryption and decryption is controlled by the seed used for
  151. the random code generation and the initial values for the three counters
  152. used as pointers to the 103 random codes.  The ASCII codes for the
  153. characters in the password are used to compute the seed number and the
  154. initial settings for the three counters.  A seed number from 0 to 32767
  155. is computed using the ASCII codes for the first five characters of the
  156. password.  The initial setting for the counters (0 thru 99) is computed
  157. from the last six characters of the password.  If the length of the
  158. password entered in response to the prompt has less than eleven
  159. characters, the characters are repeated until they create a string of
  160. eleven or more characters.  Passwords may be more than eleven characters
  161. long however only the left-most eleven characters or spaces are used to
  162. compute the seed number and the initial values for the counters.
  163.                                                                  Page 3
  164.  
  165.      For security, passwords may be keyed in a non-display mode.  Press
  166. V for the first prompt for a visible display of the passwords.  Upper or
  167. lower case letters, numbers, spaces or symbols may be used when keying
  168. passwords.  The RANDOMIZE and RND functions do not, in some cases,
  169. generate the same sequence of random numbers on different systems or on
  170. similar systems with different versions of BASIC.  The program uses a
  171. routine for generation of random numbers that results in identical
  172. random values for the code list regardless of the system or the version
  173. of BASIC that is used to run the program.  The random code values are
  174. displayed as they are generated then the program prompts for display if
  175. the PC-CRYP2 Menu.
  176.  
  177.                        PC-CRYP2 Menu
  178.  
  179.                P  Select a New Password
  180.                T  Turn Timer On/Off
  181.                S  Encrypt & Decrypt Test Strings
  182.                F  Process Diskette Files
  183.                X  Exit/End Program
  184.  
  185.      The program selected the New Password option before the menu
  186. display since encryption or decryption cannot be done unless a password
  187. has been entered.  Use the Select New Password option to change to a
  188. different password.  Turning the timer on activates statements that
  189. accumulate the total number of characters encrypt or decrypt and the
  190. total time required.  The program uses these totals to compute and
  191. display the thruput in characters per second.
  192.  
  193.                      Encrypt & Decrypt Test Strings
  194.  
  195.      The Encrypt & Decrypt Test Strings option displays a submenu from
  196. which you may select four different types of strings for encryption and
  197. decryption.  The original, encrypt and decrypt strings are displayed.
  198. This option is primarily used to look at the pattern of characters
  199. produced when you encrypt strings of upper case, lower case and numeric
  200. characters.  Keyboard input of test records accepts ASCII codes entered
  201. with the Alt key and numeric keys.
  202.  
  203.      This option uses a subroutine with two entry points or lines, one
  204. for encryption and the other for decryption, to perform the actual
  205. encryption and decryption.  The variable CTR.SET% must to set equal to 1
  206. before using the subroutine for encryption or decryption of a file or of
  207. a group of records.  CTR.SET% is used as a flag or switch that, when set
  208. equal to 1, causes the three counters to be reset to the initial values
  209. computed from the password in use.  If the subroutine is used in other
  210. programs, do not set CTR.SET%=1 except for the first record of a file or
  211. for the first string or record of a group of strings or records.  In
  212. some cases, a character encrypts to the same character.  This is not an
  213. error; it makes any attempt at unauthoried decryption more rather than
  214. less difficult.  Character strings or records to be encrypt may have
  215. characters with character codes 0 thru 255.  Characters with ASCII codes
  216. from 0 thru 31 are not encrypt.
  217.                                                                  Page 4
  218.  
  219.      This encryption/decryption subroutine uses ASCII code 7 or Control
  220. G as an escape encryption code.  The first Control G sent to the
  221. encryption/decryption subroutine turns encryption/decryption off, the
  222. second Control G turns encryption/decryption back on.  For example,
  223. printer control sequences, instructions or messages preceeded and
  224. followed by Control G will not be encrypt.  The escape encryption code
  225. is primarily used with keyboard input to prepare header message files
  226. containing information that is to escape encryption.  Hold the Ctrl key
  227. and press the letter G key to enter the ASCII 7 escape code.  Any files
  228. or records that use Control G as a BELL (or BEEP) code must be changed
  229. to use two consecutive Control G's so that encryption/decryption will
  230. continue after the BELL codes.
  231.  
  232.                         Process Diskette Files
  233.  
  234.      The process diskette files option displays the following prompt:
  235.  
  236.                      Sequential or Direct file? s/d
  237.  
  238.      The Sequential file option can be used only with files of records
  239. that are followed by carriage return and line feed characters.  Each
  240. record is processed as a character string.  Many word or text processor
  241. programs create sequential files; if a files can be displayed with the
  242. DOS TYPE command, it can probably be processed as a sequential file.
  243. With minor exceptions, other sequential files in ASCII character format
  244. may be processed as well.  Exceptions are those files that contain ASCII
  245. codes 7, 94 or 126.  Use of these codes has certain limitations outlined
  246. in the next section.  Sequential file processing uses the same
  247. encryption/decryption subroutine as is used for encrypting and
  248. decrypting test strings.
  249.  
  250.      The Direct file option can be used with any disk(ette) file.  This
  251. option treats any file as a random or direct file of 128 byte records
  252. regardless of the fact that the file may have originally been created as
  253. a sequential file with variable length records or as a random or direct
  254. file with some record length other than 128.  The Direct file option
  255. uses an encryption/decryption subroutine that does not have any
  256. restrictions regarding ASCII codes nor does it do any lower/upper case
  257. or space conversion or permit use of the Control G escape encryption
  258. code.
  259.  
  260.                        Sequential File Processing
  261.  
  262.      If you select the sequential file option, the following prompts
  263. will be displayed:
  264.  
  265.           Enter Input  dr:filename.ext or KEYBD  _
  266.           Enter Output dr:filename.ext or NOFILE _
  267.                     Encrypt or Decrypt? e/d _
  268.           Use lower case to upper case convert? y/N _
  269.           Use space to ^(94) & ~(126) convert? Y/n _
  270.                     Print Input Text? y/N _
  271.                     Print Output Text? y/N _
  272.                                                                  Page 5
  273.  
  274.      Enter KEYBD for the input file prompt to enter records from the
  275. keyboard rather than from a diskette file.  Keyboard input is primarily
  276. used to prepare header records that contain data preceeded and followed
  277. by Control G escape encryption codes.  Records input from the keyboard
  278. may not be longer than 78 characters.  Enter NOFILE for the output file
  279. prompt if you want to print the output file but not write it to
  280. diskette.
  281.  
  282.      A yes response to the Use lower case to upper case convert? y/N
  283. prompt will result in all lower case letters being encoded as upper
  284. case letters.  This prompt is not displayed if decryption is selected
  285. since the conversion is not reversible.
  286.  
  287.      A Y(es) or Enter response to the "Use space to ^(94) & ~(126)
  288. convert?  Y/n" prompt will result in ASCII codes 94 and 126 being used
  289. as substitute codes for a space (ASCII code 32) when encrypting data.
  290. 94 is used as a substitute for 32 when the preceeding character has an
  291. ASCII code less than 96; 126 is used as the substitute character when
  292. the preceeding character has an ASCII code greater than 95.  These
  293. subtitutions are made to prevent creation of a pattern in the encrypt
  294. data that would indicate the spaces between words.  Decryption does not
  295. reverse this substitution; any ASCII code 94 or 126 that was in a
  296. string or record before encryption will be replaced by a blank in the
  297. decrypt string or record.  These two character codes seldom appear in
  298. ordinary text; their loss may not even be noticed.
  299.  
  300.      Sequential files produced by some word processor programs have
  301. records that contain format or printer control sequences that use ASCII
  302. codes 0 thru 31.  Printer control codes that use an Escape code (ASCII
  303. 27) followed by a character code will be changed, when encrypt, to
  304. other printer control codes.  Printing an encrypt file that has printer
  305. control codes may result in turning on double strike mode instead of
  306. turning off emphasized mode, etc.
  307.  
  308.      An "*C_T_R   R_E_S_E_T*" record is written as the last record of
  309. encrypt files.  Header record files and data files, encrypt with the
  310. same code number or password, may be combined or concantinated with the
  311. DOS COPY /A command.  The counter reset record at the end of each of
  312. the files that were combined forces a reset of the counters at the
  313. beginning of each section of the combined file when it is decrypt.
  314.  
  315.                            Direct File Processing
  316.  
  317.      If you select the Direct file processing option the following
  318. prompts and message will be displayed:
  319.  
  320.                    Enter Input  dr:filename.ext
  321.  
  322.                    Enter Output dr:filename.ext
  323.  
  324.                    Processing ___ strings of 128 characters
  325.                                                                  Page 6
  326.  
  327.      As each block of 128 characters is encryp or decrypt, the block
  328. number is displayed.  Since the subroutine used to encrypt/decrypt
  329. direct files does not do any code conversion or check for the Control G
  330. escape encryption code, it runs at a higher character per second speed
  331. than the sequential file encryption/decryption subroutine.  The
  332. subroutine encrypts and decrypts full sectors of 512 bytes; consequently,
  333. the encrypt and decrypt files may be larger than the original file if
  334. the original file did not use all of the last sector allocated to the
  335. file.  The decrypt "garbage" in the last sector of a file will not
  336. create a problem when processing sequential files that have a standard
  337. end-of-file code.  Decrypt direct files that do not have an explicit
  338. end-of-file record or some other method for recognizing end-of file may
  339. require supplemental processing that recognizes the decrypt "garbage".
  340. Files encrypt with the direct file option can not be concantinated since
  341. concantination may result in "garbage" data in the middle of the
  342. concantinated file.
  343.  
  344.                        Transmitting Encrypt Files
  345.  
  346.      An encrypt data file may be sent to another system for decryption
  347. using a communications link, as a diskette file or as printed copy.
  348. Since encrypt data files may contain characters or character strings
  349. corresponding to transmission control codes, encrypt files should be
  350. transmitted as eight bit binary files using XMODEM or some equivalent
  351. transmission protocol for binary files.
  352.  
  353.      Any of several schemes may be used to insure that the receiving
  354. operator knows the password required for decryption.  One scheme uses as
  355. a password an eleven digit number (a passnumber?) known to both the
  356. sender and receiver.  For the second and each succeeding message, each
  357. digit of the number is increased by one.  For example, password
  358. 12345123456 will change to 23456234567 for the second message.
  359.  
  360.      The following steps outline another scheme that encodes the
  361. password and makes it a part of an encrypt data file.
  362.  
  363. Step A  Sender and receiver agree on a key number to be used to
  364.         encode the password.  For example, the sender's Social
  365.         Security number (123 45 6789) might be used.
  366. Step B  Assume that the sender uses password 11111223344
  367.         to encrypt a file.
  368. Step C  Sender adds (without carry) the key number, repeated as
  369.         necessary, to the password numbers used for encryption.
  370.                11111223344
  371.                12345678912
  372.                23456891256
  373. Step D  The sender creates a header message file with the
  374.         number 23456891256, preceeded and followed by a
  375.         Control G escape encryption code, using the same
  376.         password to encrypt this file as was used to encrypt
  377.         the data file.  The data file is concantinated to
  378.         the header message file and the combined file is sent
  379.         to the receiver.
  380.                                                                  Page 7
  381.  
  382. Step E  Receiver recovers the password to be used for
  383.         decryption by subtracting (without carry) the key number
  384.         from the number found in the header message.
  385.                23456891256
  386.                12345678912
  387.                11111223344
  388.  
  389.                            Double Encryption
  390.  
  391.      Unauthorized decryption can be made even more improbable if the
  392. encrypt data is encrypt a second time.  A password different from that
  393. used for the first encryption must be used for the second encryption.
  394. This same password must be used to decrypt the double encrypt data; the
  395. resulting single encrypt data is decrypt with the password that was used
  396. for the first encryption.
  397.  
  398.      The following steps outline the files and conversion prompt
  399. responses required for double encryption and decryption when using
  400. sequential file processing:
  401.  
  402. Step A    Password used for this step must be used for Step D.
  403.        1  Input file - text file to be encrypt
  404.        2  Encrypt or Decrypt? e/d - press E key
  405.        3  Lower to upper case convert? - either yes or no
  406.        4  Space convert? - Yes
  407.        5  Output file - single encrypt file for input Step B 1
  408. Step B    Password used for this step must be used for Step C.
  409.        1  Input file - single encrypt file from Step A 5
  410.        2  Encrypt or Decrypt? e/d - press E key
  411.        3  Lower to upper case convert? - No
  412.        4  Space Convert? - No
  413.        5  Output file - double encrypt file for input Step C 1
  414. Step C    Password for this step must be the same as used for Step B.
  415.        1  Input file - double encrtpt file from step B 5
  416.        2  Encrypt or Decrypt? e/d - press D key
  417.        3  Lower to upper case convert? - Not displayed
  418.        4  Space convert? - No
  419.        5  Output file - single encrypt file for input Step D 1
  420. Step D    Password for this step must be the same as used for Step A.
  421.        1  Input file - single encrypt file from Step C 5
  422.        2  Encrypt or Decrypt? e/d - press D key
  423.        3  Lower to upper case convert? - Not displayed
  424.        4  Space convert? - Yes
  425.        5  Output file - copy of file input at Step A 1, file may
  426.             be upper case only if response at Step A 3 was yes
  427.  
  428.      Double encryption using direct file processing uses the same steps
  429. outlined above except sub-steps 2, 3 and 4 are not required; no prompts
  430. are displayed for these sub-steps.  Double encryption of direct files
  431. does not require that the two passwords be used in the same sequence for
  432. both encryption and decryption; either password may be used for step C
  433. so long as the other password is used for step D.
  434.                                                                  Page 8
  435.                            Miscellaneous
  436.  
  437.      Always keep a record of the password used to encrypt any file that
  438. contain critical data.  If the password used to encrypt a file is not
  439. known, the file is nothing more than computer generated garbage.
  440.  
  441.      How secure is the data in files encrypt with PC-CRYP2?  I don't
  442. know since I don't have any depth of knowledge in cryptanalysis.  Since
  443. very few encrypt files will be long enought to require recycling the
  444. million character random key, it is probably impossible to find a
  445. pattern that would be of any use in decrypting the data.  While there
  446. may be some method or technique that can be used to decrypt files that
  447. have been encrypt by PC-CRYP2, the method or technique would probably be
  448. too time consuming to be of any value.  For all practical purposes, data
  449. that has been encrypt using double encryption is probably totally secure
  450. so long as the passwords used for encryption are not known.
  451.  
  452.      All the variable names used in the program have explicitly
  453. assigned attributes (%,!,#,$) and one of the characters in a variable
  454. name is a period.  There is little likelyhood that you will have any
  455. duplication of variable names if the subroutines are merged into other
  456. programs.
  457.  
  458. ittle likelyhood that you will have any
  459. duplication of variable names if the subroutines are merged into other
  460. programs